< previous page page_812 next page >

Page 812
Table C.5 Aggregate Functions Provide Summary Information About Data in the Database
FunctionReturns
AvgThe arithmetic average of the field for the records that meet the WHERE clause
CountThe number of records that meet the WHERE clause
MinThe minimum value of the field for the records that meet the WHERE clause
MaxThe maximum value of the field for the records that meet the WHERE clause
SumThe total value of the field for the records that meet the WHERE clause
FirstThe value of the field for the first record in the recordset
LastThe value of the field for the last record in the recordset
StDevThe standard deviation of the values of the field for the records that meet the WHERE clause
StDevPThe standard deviation of the values of the field for the records that meet the WHERE clause
VarThe variance of the values of the field for the records that meet the WHERE clause
VarPThe variance of the values of the field for the records that meet the WHERE clause

note.gif In Table C.5, StDev and StDevP seem to perform the same function. The same is true of Var and VarP. The difference between the functions is that the StDevP and VarP evaluate populations where StDev and Var evaluate samples of populations. square.gif

As with other SQL functions, these aggregate functions operate only on the records that meet the filter criteria specified in the WHERE clause. Aggregate functions are unaffected by sort order. Aggregate functions return a single value for the entire recordset unless the GROUP BY clause (described in the following section) is used. If GROUP BY is used, a value is returned for each record group. Listing C.14 shows the SELECT statement used to calculate the minimum, maximum, average, and total sales amounts, as well as the total item volume from the Sales table in the sample case. Figure C.8 shows the output from this query.

 
< previous page page_812 next page >